<template>
  <div>
    <el-form :model="{}" size="medium" :inline="true" label-width="60px">
      <el-form-item label="操作栏" prop="" v-hasPermi="['remind_add']">
        <el-button type="primary" plain icon="el-icon-plus" size="medium" @click="handleAdd">规则设置</el-button>
      </el-form-item>
      <el-form-item>
        <el-switch :disabled="loading" v-model="query.remindFlag" @change="handlerChange" :active-value="'0'"
          :inactive-value="'1'" active-text="开启提醒" inactive-text="关闭提醒">
        </el-switch>
      </el-form-item>
      <el-form-item>
        <el-switch :disabled="loadingtwo" v-model="query.broadcastFlag" @change="handlerChange" :active-value="'0'"
          :inactive-value="'1'" active-text="开启播报" inactive-text="关闭播报">
        </el-switch>
      </el-form-item>
    </el-form>
    <template v-if="open">
      <AddbaseValue :title="title"></AddbaseValue>
    </template>
  </div>
</template>

<script>
import { Updaterule, getremindFlag, getruleList } from "@/api/system/difftype.js";
export default {
  components: {
    AddbaseValue: () => import('../form/addbaseValue.vue')//添加子组件
  },
  data () {
    return {
      title: '添加项目',
      open: false,
      loading: false,
      loadingtwo: false,
      query: {
        remindFlag: '0',
        broadcastFlag: '0'
      }
    }
  },
  watch: {
    'query.remindFlag' (val) {
      if (val == '1') {
        this.loadingtwo = true
        this.query.broadcastFlag = '1'
      } else {
        this.loadingtwo = false

      }
    }
  },
  mounted () {
    this.getinit();
  },
  methods: {
    async getinit () {
      let { data: data } = await getremindFlag()
      this.query = data
    },
    async handlerChange () {
      this.loading = true
      let params = {
        ...this.query
      }
      let data = await Updaterule(params)
      if (data.code == 200) {
        getruleList().then(res => {//存储提醒管理的规则
          let data = res.data.list.map(item => {
            return {
              ...item,
              play: 1
            }
          })
          sessionStorage.setItem('ruleList', JSON.stringify(data))
          this.$store.commit('SET_RULELIST', data)
        })
        this.$message.success('操作成功')
      } else {
        this.$message.error(data.msg)
      }
      this.loading = false

    },
    /** 新增按钮操作 */
    handleAdd () {
      this.open = true
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.$emit('selectList')
    },
    /** 删除按钮操作 */
    handleDelete (row) {

    },
  }
}
</script>

<style>

</style>